var e = require;
var t = module;
var o = exports;
var n;
function i(e, t) {
    return (i =
        Object.setPrototypeOf ||
        function (e, t) {
            return (e.__proto__ = t), e;
        })(e, t);
}
(o.__esModule = !0), (o.default = void 0);
var a = (function (e) {
    var t, o;
    function n() {
        return e.call(this) || this;
    }
    (o = e), ((t = n).prototype = Object.create(o.prototype)), (t.prototype.constructor = t), i(t, o);
    var a = n.prototype;
    return (
        (a.init = function () {
            (this.env = window.swan),
                (this.info = (window.lplatform && lplatform.systemInfo) || this.env.getSystemInfoSync()),
                (this.bh = lplatform.cparam.bannerHeight || 170),
                (this.bw = lplatform.cparam.bannerWidth || Math.min(this.info.windowWidth, (16 * this.bh) / 9)),
                (this.gameRecorderManager = this.env.getVideoRecorderManager()),
                this.createMoreGameButton(),
                this.showShareMenu();
        }),
        (a.initAD = function () {
            this.loadBanner(!1), this.createRewardedVideo(!1);
        }),
        (a.loadBanner = function (e) {
            this.hideBanner(!0),
                this.bannerAd ||
                    ((this.btop = 0),
                    lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - this.bh),
                    (this.bannerAd = this.env.createBannerAd({
                        adUnitId: lplatform.cparam.bannerID,
                        appSid: lplatform.cparam.appSid,
                        adIntervals: 30,
                        style: {
                            width: this.bw,
                            height: this.bh,
                            left: (this.info.windowWidth - this.bw) / 2,
                            top: this.btop
                        }
                    })),
                    this.bannerAd.onLoad(this.onBannerLoad.bind(this)),
                    this.bannerAd.onError(this.onBannerError.bind(this)),
                    this.bannerAd.onResize(this.onBannerResize.bind(this))),
                (this.bannerAutoShow = e);
        }),
        (a.onBannerResize = function (e) {
            (this.btop = 0),
                lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - e.height),
                (this.bannerAd.style.top = this.btop),
                (this.bannerAd.style.left = 0);
        }),
        (a.createRewardedVideo = function (e) {
            lplatform.cparam.rewardedVideoID &&
                (this.rewardedVideoAd ||
                    "function" != typeof this.env.createRewardedVideoAd ||
                    ((this.rewardedVideoAd = this.env.createRewardedVideoAd({
                        adUnitId: lplatform.cparam.rewardedVideoID,
                        appSid: lplatform.cparam.appSid
                    })),
                    this.rewardedVideoAd.onError(this.onRewardedVideoError.bind(this)),
                    this.rewardedVideoAd.onClose(this.onRewardedVideoClose.bind(this)),
                    this.rewardedVideoAd.onLoad(this.onRewardedVideoLoad.bind(this))),
                e && this.showRewardedVideo(window.vcb));
        }),
        (a.showRewardedVideo = function (t) {
            lplatform.pauseGame(), e.prototype.showRewardedVideo.call(this, t);
        }),
        (a.onRewardedVideoError = function (t, o) {
            e.prototype.onRewardedVideoError.call(this, t, o), lplatform.resumeGame();
        }),
        (a.onRewardedVideoClose = function (t) {
            e.prototype.onRewardedVideoClose.call(this, t), lplatform.resumeGame();
        }),
        (a.loadInterstitial = function () {}),
        (a.onInterstitialClose = function () {}),
        (a.showInterstitial = function () {}),
        (a.hideInterstitial = function () {}),
        (a.showFavoriteGuide = function () {
            lplatform.plog("PBaiDu,showFavoriteGuide"),
                "function" == typeof this.env.showFavoriteGuide &&
                    this.env.showFavoriteGuide({type: "tip", content: "一键添加到我的小程序"});
        }),
        (a.showAddToDesktopGuide = function () {
            "function" == typeof this.env.showAddToDesktopGuide &&
                this.env.showAddToDesktopGuide({
                    type: "bar-autohide",
                    content: "一键添加到我的桌面",
                    success: function success(e) {
                        console.log("添加成功：", e);
                    },
                    fail: function fail(e) {
                        console.log("添加失败：", e);
                    }
                });
        }),
        (a.showShareMenu = function () {
            "function" == typeof this.env.showShareMenu &&
                this.env.showShareMenu({
                    success: function success() {},
                    fail: function fail() {},
                    complete: function complete() {}
                }),
                this.env.onShareAppMessage(function () {
                    return {
                        title: lplatform.cparam.shareAppTitle,
                        imageUrl: lplatform.cparam.shareAppImgUrl,
                        query: "key1=1&key2=2&key3=3",
                        success: function success(e) {
                            lplatform.plog("onShareAppMessage share success", JSON.stringify(e));
                        },
                        fail: function fail(e) {
                            lplatform.plog("onShareAppMessage share fail", JSON.stringify(e));
                        }
                    };
                });
        }),
        (a.shareAppMessage = function () {
            this.env.shareAppMessage({
                title: lplatform.cparam.shareAppTitle,
                imageUrl: lplatform.cparam.shareAppImgUrl
            });
        }),
        (a.canRecord = function () {
            return (
                !(!this.gameRecorderManager || !lplatform.cparam.canRecord) ||
                (lplatform.plog("PBaiDu,不支持录制游戏画面"), !1)
            );
        }),
        (a.startRecord = function (e) {
            if (this.canRecord()) {
                lplatform.plog("startRecord"),
                    (this.recordStartCb = e),
                    (this.videoPath = null),
                    this.gameRecorderManager.start({duration: 30}),
                    this.gameRecorderManager.onStart(this.onGameRecordStart.bind(this)),
                    this.gameRecorderManager.onError(this.onGameRecordError.bind(this)),
                    this.gameRecorderManager.onStop(this.onGameRecordStop.bind(this));
                var t = this;
                this.env.onShow(function () {
                    lplatform.plog("startRecord this.env.onShow"), t.resumeRecord();
                }),
                    this.env.onHide(function () {
                        lplatform.plog("startRecord this.env.onHide"), t.pauseRecord();
                    });
            }
        }),
        (a.onGameRecordStart = function () {
            lplatform.plog("PBaiDu,onGameRecordStart"),
                (this.gameRecordStartTime = Date.now()),
                this.recordStartCb && (this.recordStartCb(), (this.recordStartCb = null));
        }),
        (a.onGameRecordError = function (e) {
            lplatform.plog("onGameRecordError:" + JSON.stringify(e), "error");
        }),
        (a.onGameRecordStop = function (e) {
            lplatform.plog("onGameRecordStop this.recordStopCb:" + this.recordStopCb),
                (this.gameRecordStopTime = Date.now()),
                this.gameRecordStopTime - this.gameRecordStartTime > 4500
                    ? (this.videoPath = e.videoPath)
                    : lplatform.plog("onGameRecordStop 实际录屏时间少于5秒就有可能分享失败"),
                this.recordStopCb && (this.recordStopCb(this.videoPath), (this.recordStopCb = null));
        }),
        (a.pauseRecord = function () {
            this.gameRecorderManager.pause();
        }),
        (a.resumeRecord = function () {
            this.gameRecorderManager.resume();
        }),
        (a.stopRecord = function (e) {
            lplatform.plog("stopRecord cb:" + e),
                this.canRecord() && ((this.recordStopCb = e), this.gameRecorderManager.stop());
        }),
        (a.shareRecord = function (e, t) {
            lplatform.plog("PBaiDu,shareRecord videoPath:" + this.videoPath),
                this.canShareRecord()
                    ? this.env.shareVideo({
                          videoPath: this.videoPath,
                          success: function success() {
                              e && e();
                          },
                          fail: function fail(e) {
                              t && t(e);
                          }
                      })
                    : this.shareAppMessage();
        }),
        (a.resetRecord = function () {
            this.stopRecord(), (this.videoPath = null);
        }),
        (a.createMoreGameButton = function () {
            this.createRecommendationButton();
        }),
        (a.createMoreGameBanner = function () {}),
        (a.createMoreGamePortal = function () {}),
        (a.createRecommendationButton = function () {
            if ("function" == typeof this.env.createRecommendationButton)
                if (this.moreGameBtn) this.moreGameBtn.show();
                else {
                    this.moreGameBtn = this.env.createRecommendationButton({
                        type: "list",
                        style: {
                            left: lplatform.cparam.moreGameLeft * lplatform.systemInfo.windowWidth,
                            top: lplatform.cparam.moreGameTop * lplatform.systemInfo.windowHeight
                        }
                    });
                    var e = this;
                    this.moreGameBtn.onLoad(function () {
                        e.moreGameBtn.show(), e.moreGameBtn.offLoad(function () {});
                    }),
                        this.moreGameBtn.load();
                }
        }),
        (a.makeShareUI = function (e, t, o, n, i) {
            void 0 === n && (n = 0),
                void 0 === i && (i = !1),
                lplatform.uiEngine.CreateShareK(
                    function () {
                        this.shareRecord(e, t);
                    }.bind(this),
                    function () {
                        t && t(), this.gameRecordShareBtn && this.gameRecordShareBtn.hide();
                    }.bind(this),
                    o,
                    n,
                    i
                );
        }),
        (a.goToGameOrGameList = function () {
            this.navigateToMiniProgram();
        }),
        (a.navigateToMiniProgram = function (e) {
            this.env.navigateToMiniProgram({
                appKey: e || lplatform.cparam.navigateToId[0],
                path: "/path/page/0",
                extraData: {},
                success: function success(e) {
                    console.log("navigateToMiniProgram success", e);
                },
                fail: function fail(e) {
                    console.log("navigateToMiniProgram fail", e);
                }
            });
        }),
        n
    );
})(((n = e("PWX")) && n.__esModule ? n : {default: n}).default);
(o.default = a), (t.exports = o.default);
